<?php

namespace App\Models\Application;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class ColumnRecommendData
 * @package App\Models\Application
 * @version July 3, 2018, 7:44 pm CST
 *
 * @property \App\Models\Application\Data data
 * @property string name
 * @property string title
 * @property integer data_id
 * @property integer resource_data_id
 * @property string onclick
 * @property string img
 * @property integer order
 */
class ColumnRecommendData extends Model
{
    use SoftDeletes;

    public $table = 'column_recommend_datas';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'name',
        'title',
        'data_id',
        'resource_data_id',
        'onclick',
        'img',
        'order',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name'             => 'string',
        'title'            => 'string',
        'data_id'          => 'integer',
        'resource_data_id' => 'integer',
        'onclick'          => 'string',
        'img'              => 'string',
        'order'            => 'integer',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [

    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function data()
    {
        return $this->hasOne(\App\Models\Entity\Column\Data::class, 'id', 'data_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * 栏目推荐数据
     **/
     public function columnRecommendDatas()
    {
        return $this->belongsToMany(\App\Models\Entity\Column\Data::class, 'columnrec_column_recommend_datas', 'columnrec_id', 'column_recommend_data_id');
    }
}
